package com.Lemon.Zhkuhealth.admin.controller;

import com.Lemon.Zhkuhealth.common.constant.MessageConstant;
import com.Lemon.Zhkuhealth.common.pojo.entity.User;
import com.Lemon.Zhkuhealth.common.pojo.vo.UserVo;
import com.Lemon.Zhkuhealth.common.util.R;
import com.Lemon.Zhkuhealh.api.service.IUserService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

@RestController
@RequestMapping("/login")
public class LoginController {

    @DubboReference
    private IUserService userService;

    @PostMapping
    public R login(@RequestBody UserVo userVo) {
        String username = userVo.getUsername();
        String password = userVo.getPassword();

        // 调用服务层方法根据用户名查询用户
        User user = userService.findByUsername(username);

        if (user != null && user.getPassword().equals(password)) {
            return new R(true, MessageConstant.LOGIN_SUCCESS, user);
        }
        return new R(false, "用户名或密码错误");
    }
}